const fs = require('fs')

module.exports = (data) => {
    return new Promise((reslove, reject) => {
        fs.readFile('./database/comments.json', 'utf-8', (err, commentsStr)=> {
            const comments = JSON.parse(commentsStr)
            comments.comments.unshift(data)
            fs.writeFile('./database/comments.json', JSON.stringify(comments), (err, res) => {
                if (err) {
                    reject(err)
                } else {
                    reslove(res)
                }
            })

        })
    })
}